package com.appspot.diasporajava.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.appspot.diasporajava.dao.PostDao;
import com.appspot.diasporajava.entities.Post;

//@Component
public class PostDaoJPA extends GenericDaoJPAImpl<Post,Long> implements PostDao<Post,Long>{
	/* (non-Javadoc)
	 * @see com.appspot.diasporajava.dao.jpa.PostDao#findByUserId(java.lang.Long)
	 */
	@Override
	public List<Post> findByUserId(Long userId){
		final StringBuffer queryString = new StringBuffer("SELECT o from ");
		queryString.append(type.getSimpleName()).append(" o ");
		queryString.append(" where userId = ").append(userId);

		EntityManager em = this.emf.createEntityManager();
		final Query query = em.createQuery(queryString.toString());
		//final Query query = this.em.createQuery(queryString.toString());
		List<Post> posts=(List<Post>)query.getResultList();
		em.close();
		return posts;
	}
}
